-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] fix: UnboundLocalError incorrectly raised as AttributeError #20085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
fixes mypyc/mypyc#1151 I'm not entirely sure what the difference is between emit_attribute_error and the code block that I edited I'm not sure if we need to update both cases, but I know we do need to handle it in this one
| attr.removeprefix(GENERATOR_ATTRIBUTE_PREFIX), | ||
| op.traceback_entry[1], | ||
| globals_static, | ||
| if class_ir.is_generated: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this here so it will do its job in any place emit_attribute_error might be used in the future, it didn't seem appropriate to add another helper but this doesn't really seem appropriate either
| ) | ||
| ) | ||
| var_name = op.attr.removeprefix(GENERATOR_ATTRIBUTE_PREFIX) | ||
| if cl.is_generated: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better approach would be to add a new flag to ClassIR such as is_environment that is set when the attributes represent local variables. This way if we add a new kind of generated class that doesn't represent locals, AttributeError will be used.
fixes mypyc/mypyc#1151